from django.contrib import admin

# Register your models here.

from .models import Book ,Author

#定义模型管理器类
class BookManager(admin.ModelAdmin):
    #控制哪些字段会显示在Admin的修改列表页面中
    list_display = ['id' , 'title' , 'price' , 'market_price']
    #list_display_links可以控制list_display中的字段是否应该链接到对象的"更改"页面
    list_display_links = ['title']
    #list_filter设置激活Admin修改列表页面右侧栏中的过滤器
    list_filter = ['title']
    #search_fields设置启用Admin更改列表页面上的搜索框
    search_fields = ['title']
    #list_editable设置为模型上的字段名称列表,这将允许再更改列表页面上进行编辑
    list_editable = ['price' , 'market_price']

class AuthorsManage(admin.ModelAdmin):
    list_display = ['id' , 'name' , 'age']
    list_display_links = ['name']
    list_filter = ['name']
    search_fields = ['name']
    list_editable = ['age']


#将模型管理器绑定到Book模型并且进行注册
admin.site.register(Book , BookManager)
admin.site.register(Author , AuthorsManage)